﻿using System;
using System.Collections.Generic;
using System.Text;
using SharpObjects.SearchEngine.Common.Search;

namespace SharpObjects.SearchEngine.Common.QueryConstraints
{
    public class GroupQueryConstraint : IQueryConstraint
    {
        public enum eQueryLogic { AND, OR }

        public GroupQueryConstraint()
        {
            this.Constraints = new List<IQueryConstraint>();
            this.ConstraintId = Guid.NewGuid();
        }

        public Guid ConstraintId { get; set; }

        public eQueryLogic Logic { get; set; }
        public List<IQueryConstraint> Constraints { get; set; }
        public bool ShowFieldName { get; set; } 

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            for(int k = 0; k < this.Constraints.Count; k++)
            {
                this.Constraints[k].ShowFieldName = this.ShowFieldName;

                sb.Append(this.Constraints[k].ToString());

                if(k < (this.Constraints.Count - 1))
                {
                    sb.Append(string.Format(" {0} ", this.Logic.ToString()));
                }
            }

            return sb.ToString();
        }

    }
}
